package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemServiceQuoteBinding;
import com.sgb.kjwl.model.entity.enterprise.ServiceQuoteEntity;
import com.sgb.kjwl.view.ui.activity.enterprise.SeverQuoteDetailActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

public class ServiceQuoteAdapter extends BaseRecycleAdapter<ServiceQuoteEntity> {

    Context context;
    ItemServiceQuoteBinding binding;

    public ServiceQuoteAdapter(Context context, List<ServiceQuoteEntity> datas) {
        super(context, R.layout.item_service_quote, datas);
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, ServiceQuoteEntity serviceQuoteEntity) {
        holder.setBinding(BR.viewModel, serviceQuoteEntity);

        binding = (ItemServiceQuoteBinding) holder.getmBinding();
        holder.getItem().setOnClickListener(view ->
                SeverQuoteDetailActivity.start(context, serviceQuoteEntity)
        );
        if (serviceQuoteEntity.getService_date() != null && !serviceQuoteEntity.getService_date().contains("-")) {
            long serviceDate = Long.parseLong(serviceQuoteEntity.getService_date());
            binding.tvDate.setText(DateUtils.timestampToDate(serviceDate));
        } else {
            binding.tvDate.setText(serviceQuoteEntity.getService_date());
        }
    }

//
//    private void showDialog(ServiceQuoteEntity serviceQuoteEntity) {
//        LayoutInflater inflater = LayoutInflater.from(context);
//        View layout = inflater.inflate(R.layout.popwindow_service_quote, null);
//        AlertDialog dialog;
//        AlertDialog.Builder builder = new AlertDialog.Builder(context);
//        builder.setView(layout);
//        builder.setCancelable(true);
//        dialog = builder.show();
//        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
//
//        DisplayMetrics dm = new DisplayMetrics();
//        //获取屏幕信息
//        dm = context.getResources().getDisplayMetrics();
//        int screenWidth = dm.widthPixels;
//        int screenHeigh = dm.heightPixels;
//        CardView cv = dialog.findViewById(R.id.cv_dialog);
//        LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) cv.getLayoutParams(); //取控件textView当前的布局参数
//        linearParams.width = screenWidth - 100;//
//        linearParams.height = screenHeigh / 3;//
//        cv.setLayoutParams(linearParams);
//
//        TextView titleView = dialog.findViewById(R.id.title_view);
//        TextView price = dialog.findViewById(R.id.tv_price);
//        TextView date = dialog.findViewById(R.id.tv_date);
//        TextView enterprise = dialog.findViewById(R.id.tv_enterprise);
//        TextView detail = dialog.findViewById(R.id.tv_detail);
//
//        if (serviceQuoteEntity != null) {
//            titleView.setText(serviceQuoteEntity.getName());
//            price.setText("￥" + serviceQuoteEntity.getPrice());
////            date.setText(serviceQuoteEntity.getService_date());
//            enterprise.setText(serviceQuoteEntity.getCompanyName());
//            detail.setText(serviceQuoteEntity.getProfile());
//
//            if (serviceQuoteEntity.getService_date() != null && !serviceQuoteEntity.getService_date().contains("-")) {
//                long serviceDate = Long.parseLong(serviceQuoteEntity.getService_date());
//                date.setText(DateUtils.timestampToDate(serviceDate));
//            } else {
//                date.setText(serviceQuoteEntity.getService_date());
//            }
//        }
//        dialog.findViewById(R.id.iv_cancel).setOnClickListener(v -> dialog.dismiss());
//    }
}
